<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<c:set var="reportTitle" value="稼动率报表" />

<%@ include file="/common/report_head.jsp" %>
<%@ include file="/condition/sartTime_YMDH_input.html"%>
<%@ include file="/condition/endTime_YMDH_input.html"%>
<%@ include file="/condition/fab_sumo_must.html"%>
<%@ include file="/condition/line_sumo.html"%>
<%@ include file="/condition/toolg_sumo.html"%>
<%@ include file="/condition/tool_sumo.html"%>
<%@ include file="/condition/shift_sumo.html"%>
<%@ include file="/condition/toolStat_sumo.html"%>
<%@ include file="/condition/groupBy_radio.html"%>

<%@ include file="/common/report_middle.jsp" %>
<div class="col-md-12" style="height: 820px;">
    <div id="pqGrid"></div>
</div>
<%@include file="/common/report_end.jsp" %>



<script>
    $(document).ready(function () {
        $("title").text("稼动率报表");

        $('#query_btn').click(function (){
            initGridAndChart();
            ajax('/jn-report/report/activation_new_report.do' ,loadConditionMapData(), true, ajax_successful);

            function ajax_successful(outTrxObj) {
                if(outTrxObj.gridData.length < 1) { showMessengerDialog("数据查询为空"); return false; }

                // Grid表格动态列
                var colM = [{halign:"center",align:'center', dataIndx: 'line_id',     title: '线别',   width: 140,   editable: false, sortable: true}];
                if ($.trim($("#groupByRadio input:checked").val()) == "TOOLG" || $.trim($("#groupByRadio input:checked").val()) == "TOOL") {
                    colM.push({halign:"center",align:'center', dataIndx: 'toolg_id',    title: '设备组', width: 200,   editable: false, sortable: true});
                }
                if ($.trim($("#groupByRadio input:checked").val()) == "TOOL") {
                    colM.push({halign:"center",align:'center', dataIndx: 'tool_id',     title: '设备',   width: 200,   editable: false, sortable: true});
                }
                if ($.trim($("#shiftIdSumo").val()).indexOf("D") != -1 || $.trim($("#shiftIdSumo").val()).indexOf("N") != -1) {
                    colM.push({halign:"center",align:'center', dataIndx: 'shift_id',	title: '班别',   width: 50,    editable: false, sortable: true});
                }
                colM.push({halign:"center",align:'center', dataIndx: 'stat',        title: '状态',   width: 90,    editable: false, sortable: true});
                for (var i=0; i<outTrxObj.dynamicColumn.length; i++){
                    var date = outTrxObj.dynamicColumn[i];
                    colM.push({halign:'center', align:'center',  dataIndx: date, title: date, width: 100, editable: false, sortable: true});
                }
                _pqUtil.f.setColModel($("#pqGrid"), colM);
                _pqUtil.f.seTitle($("#pqGrid"), outTrxObj.gridTitle);
                _pqUtil.f.loadPqGridData($("#pqGrid"), outTrxObj.dynamicColumnJsonGridData);

                // 合并单元格
                cellMerge($("#pqGrid"), true);
                function cellMerge(grid, refresh) {
                    var mergeCells = [];
                    var CM = grid.pqGrid("option", "colModel");
                    var data = grid.pqGrid("option", "dataModel.data");
                    var col_length = 0;
                    for (var i=0; i< CM.length; i++) {
                        if (['厂别','线别','设备组','设备','班别'].indexOf(CM[i].title) != -1) col_length ++;
                    }
                    while (col_length--) {
                        var dataIndx = CM[col_length].dataIndx;
                        var data_length = data.length;
                        var rc = 1;
                        var merge_style = '';
                        while (data_length--) {
                            var cd = data[data_length][dataIndx];
                            var cd_prev = data[data_length - 1] ? data[data_length - 1][dataIndx] : undefined;
                            if (cd_prev !== undefined && cd == cd_prev) {
                                rc++;
                            }else if (rc > 1) {
                                mergeCells.push({ r1: data_length, c1: col_length, rc: rc, cc: 1, style: merge_style });
                                rc = 1;
                            }
                        }
                    }
                    grid.pqGrid("option", "mergeCells", mergeCells);
                    if (refresh) grid.pqGrid("refreshDataAndView");
                };
            };
        });
    });
</script>
